<template>
  <section class="jumbotron">
    <h3 class="jumbotron-heading">Search Github Users</h3>
    <div>
      <input type="text" placeholder="enter the name you search" v-model="keyword"/>
      &nbsp;<button @click="searchUsers(keyword)">Search</button>
    </div>
  </section>
</template>

<script>
import axios from "axios";

export default {
  name: "Search",
  data() {
    return {
      keyword: ''
    }
  },
  props: {},
  computed: {},
  components: {},
  methods: {
    searchUsers(keyword) {
      this.$bus.$emit('bus_updateList', {
        isFirst: false,
        isLoading: true,
        errMsg: '',
        users: []
      });
      axios.get('https://api.github.com/search/users?q=' + keyword).then(resp => {
        this.$bus.$emit('bus_updateList', {
          isLoading: false,
          errMsg: '',
          users: resp.data.items
        });
      }, err => {
        this.$bus.$emit('bus_updateList', {
          isLoading: false,
          errMsg: err.message,
          users: []
        });
      });
    },
  },
  mixins: [],
  watch: {},
  filters: {},
  directives: {}
}
</script>

<style scoped>

</style>